package cn.xiyun.xiyuncc.MQ.consumer;

import cn.xiyun.xiyuncc.domain.PayOrder;
import cn.xiyun.xiyuncc.dto.Order2PayDto;
import cn.xiyun.xiyuncc.service.IPayOrderService;
import com.alibaba.fastjson.JSON;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(
        consumerGroup = "createOrder-message-group",
        topic = "createOrder_topic",
        selectorExpression="createOrder_tags"
        )
public class OrderPayConsumer implements RocketMQListener<String> {
    @Autowired
    private IPayOrderService payOrderService;

    @Override
    public void onMessage(String message) {
        Order2PayDto order2PayDto = JSON.parseObject(message, Order2PayDto.class);
        PayOrder payOrder = payOrderService.selectOrderNo(order2PayDto.getOrderNo());
        if (payOrder != null){
            return;
        }
        payOrderService.orderTOPay(order2PayDto);
    }
}
